package com.tianhao.rocketmq.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @author: tianhao.luo@hand-china.com 2020/12/13  14:26
 */
public class SyncProducer {

    public static void main(String[] args) throws Exception {
        // 创建一个DefaultMQProducer对象
        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
        // 关联地址
        producer.setNamesrvAddr("192.168.15.78:9876");
        // 启动
        producer.start();
        // 发送消息
        for (int i = 0; i < 100; i++) {
            Message msg = new Message("TopicTest", "TagA", ("Hello RocketMQ" + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n",sendResult);
        }
        producer.shutdown();
    }
}
